package com.glsc.ngateway.platform.controller.it.networkassets;

import com.glsc.ngateway.common.api.platform.resp.PlatformResponse;
import com.glsc.ngateway.common.api.platform.dto.it.networkassets.dict.ItNetworkAssetsDictDto;
import com.glsc.ngateway.platform.service.it.networkAssets.dict.ItNetworkAssetsDictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.logging.log4j.util.Strings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/it/networkAssets/dict")
@Api(value = "网络资产-字典", tags = {"网络资产"})
public class ItNetworkAssetsDictController {

    private static final Logger logger = LoggerFactory.getLogger(ItNetworkAssetsDictController.class);

    @Autowired
    private ItNetworkAssetsDictService dictService;

    /**
     * 查询
     */
    @PostMapping("/search")
    @ApiOperation(value = "查询字典", notes = "查询字典")
    public PlatformResponse<List<ItNetworkAssetsDictDto>> query(@RequestBody ItNetworkAssetsDictDto queryParam){
        return PlatformResponse.successData(dictService.queryAll(queryParam, Strings.isBlank(queryParam.getCode())));
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除字典", notes = "删除字典")
    public PlatformResponse<Void> delete(@RequestBody ItNetworkAssetsDictDto param){
        dictService.delete(param.getId());
        return PlatformResponse.successMsg("删除成功");
    }

    /**
     * 添加或修改
     */
    @PostMapping("/addOrUpdate")
    @ApiOperation(value = "添加或修改字典", notes = "添加或修改字典")
    public PlatformResponse<Void> addOrUpdate(@RequestBody ItNetworkAssetsDictDto param){
        dictService.addOrUpdate(param);
        return PlatformResponse.successMsg("添加成功");
    }

}
